package com.jyb.util;

public class CheckUserUtil {

	public static String encode (String username){
		return JiaJie.strEncode(username+","+JiaJie.pubKey+","+System.currentTimeMillis(), JiaJie.pubKey, JiaJie.priKey);
	}
	
	public static boolean isValid(String str){
		if(!StringUtils.isEmpty(str)){
			String strr=JiaJie.strDecode(str, JiaJie.pubKey, JiaJie.priKey);
			if(strr.indexOf(","+JiaJie.pubKey+",")>-1){
				return true;
			}
		}
		return false;
	}
	
	public static String decode(String str){
		if(!StringUtils.isEmpty(str)){
			return JiaJie.strDecode(str, JiaJie.pubKey, JiaJie.priKey);
		}
		return null;
	}
	
	public static String getUsername(String token){
		if(token==null){
			return null;
		}
		String str=CheckUserUtil.decode(token);
		return str.split(",")[0];
	}
}
